
#! /bin/bash
root_path=$(pwd)
build_path=$root_path/ut_mybuild
SHDIR=$(dirname $(realpath $0))

if [ -e ut_mybuild ]
then
    cd ut_mybuild
    rm -r ./*
else
    mkdir ut_mybuild
    cd ut_mybuild
fi

paltform_array=("x86_zmq" "x86_dds" "8155" "xavier" "821" "orin_qnx" "orin_linux")
num=${#paltform_array[@]}

if [ $# -eq 1 ]
then
    platform_code=$1
    # interface_version=$2
else
    echo "请选择编译代码："
    for (( i=0; i<num;i++))
    do
        echo $i--${paltform_array[$i]}
    done
    echo -------
    read platform_code
fi

if [ $platform_code -ge $num ]
then
    echo "输入错误，请确认"
    return
fi

echo "-------- 通信中间件-- ${paltform_array[$platform_code]}"

if [ ${platform_code} == 0 ]
then
    cd $build_path
    # cmake -Dplatform=x86 -Dinterface=${interface_version} ..
    cmake -DCMAKE_TOOLCHAIN_FILE=$SHDIR/../../release/common/cmake/toolchain_x86_64.cmake ..
fi

if [ ${platform_code} == 1 ]
then
    cd $build_path
    cmake -Dplatform=x86 -Dinterface=${interface_version} -DUSE_DDS=1 ..
fi

if [ ${platform_code} == 2 ]
then
    cd $build_path
    source /opt/capilot/script/env_8155.sh
    cmake -Dplatform=8155 -Dinterface=${interface_version} ..
fi

if [ ${platform_code} == 3 ]
then
    cd $build_path
    source /opt/capilot/script/env_xavier.sh
    cmake -Dplatform=xavier -Dinterface=${interface_version} -DUSE_DDS=1 ..
fi

if [ ${platform_code} == 4 ]
then
    cd $build_path
    source /opt/capilot/script/env_821.sh
    cmake -Dplatform=821 -Dinterface=${interface_version} ..
fi

if [ ${platform_code} == 5 ]
then
    cd $build_path
    source /opt/capilot/script/env_orin_qnx.sh
    cmake -Dplatform=orin_qnx -Dinterface=${interface_version} -DUSE_DDS=1 ..
fi

if [ ${platform_code} == 6 ]
then
    cd $build_path
    source /opt/capilot/script/env_orin_linux.sh
    cmake -Dplatform=orin_linux -Dinterface=${interface_version} -DUSE_DDS=1 ..
fi

make -j8

